﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aulac.Rsc.Bss.Tags;
using Aulac.Global.Xml;
using System.Xml;
using Aulac.Srv.Db.Connect;
using Aulac.Srv.Db.Common;
using Aulac.Global.Common;
using Aulac.Rsc.Bss;
using Aulac.Srv.Data.XmlQuery;

namespace Aulac.Srv.Db.Data.Ems.Items.RptLists
{
    public partial class BuyCapAss : Aulac.Srv.Db.Data.Ems.Document.DbEmsDataDocumentMangager
    {
        public BuyCapAss(IDbAulacConnect p_Db)
            : base(p_Db)
        {

        }

        /// <summary>
        /// Add thong tin mot phieu mua hang.
        /// </summary>
        public XmlDataDocument AddVchBuyCapAss(XmlDataDocument xmlData)
        {
            try
            {
                return null;
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Cap nhat thong tin cua mot phieu mua hang.
        /// </summary>
        public XmlDataDocument UpdateVchBuyCapAss(XmlDataDocument xmlData)
        {
            try
            {
                return null;
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Xoa mot phieu mua hang.
        /// </summary>
        public XmlDataDocument DelVchBuyCapAss(XmlDataDocument xmlData)
        {
            try
            {
                string sVchBuyCappAssPrkID = XmlProcess.GetValueParam(xmlData, tagVch.VchBuyHeaderCapAss.VchBuyCapAssPrkID);
                return ExecQueryDelVchBuyCapAss(sVchBuyCappAssPrkID);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Get thông tin chi tiết của một phiếu.
        /// </summary>
        /// <param name="xmlData"></param>
        /// <returns></returns>
        public XmlDataDocument GetDetailBuyCapAss(XmlDataDocument xmlData)
        {            
            try
            {
                string sVchBuyCapAssPrkID = XmlProcess.GetValueParam(xmlData, tagVch.VchBuyHeaderCapAss.VchBuyCapAssPrkID);
                return ExecQueryGetDetailBuyCapAss(sVchBuyCapAssPrkID);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
          
        }

        /// <summary>
        /// Get danh sach các phiếu.
        /// </summary>
        /// <param name="xmlData"></param>
        /// <returns></returns>
        public XmlDataDocument GetListDetailBuyCapAss(XmlDataDocument xmlData)
         {                         
             string sVchDateFrom = XmlProcess.GetValueParam(xmlData, tagGeneral.VchFromDate);
             string sVchDateTo = XmlProcess.GetValueParam(xmlData, tagGeneral.VchToDate);
             return ExecQueryGetListDetailBuyCapAss(sVchDateFrom, sVchDateTo);
         }

        public XmlDataDocument GetNewVchNo(XmlDataDocument xmlData)
        {
            string sVchTypeID = XmlProcess.GetValueParam(xmlData, tagVch.VchBuyHeaderCapAss.VchTypeID);
            XmlDataDocument xmlOutDoc = CreateXmlDocument("", "");
            string sVchName = "";
            string sVchNo = GetNewVchNo(TableNames.VchHeaderBuyCapAss, tagVch.VchBuyHeaderCapAss.VchNo, sVchTypeID, ref sVchName);
            XmlProcess.SetAtrbVchHeader(xmlOutDoc, tagVch.VchBuyHeaderCapAss.VchNo, sVchNo);
            XmlProcess.SetAtrbVchHeader(xmlOutDoc, tagVch.VchBuyHeaderCapAss.VchName, sVchName);
            return xmlOutDoc;
        }

        #region Private Methods
        private bool DelDbTableVchBuy(string pTableName, string pTagKey, string pValueKey)
        {
            try
            {
                string sqlQuery = SqlHelper.CreateSqlDelete(pTableName, pTagKey);
                return DbDataProvider.ExecuteNonQuery(ref this.mDbCmd, sqlQuery, pValueKey) > 0 ? true : false;
                // AddDbTableVchBuy("Tbale", new string[]{tagItems.RptList.RptPrkID, tagItems.RptList.TableName, tagItems.RptList.RptName});

            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
        private bool AddDbTableVchBuy(string pTableName, string[] ArrL, params object[] arrValues)
        {
            try
            {
                string sqlQuery = SqlHelper.CreateSqlInsert(pTableName, ArrL);
                DbDataProvider.SelectMaxID(pTableName, tagVch.VchBuyHeaderCapAss.VchBuyCapAssPrkID);
                return DbDataProvider.ExecuteNonQuery(ref this.mDbCmd, sqlQuery, arrValues) > 0 ? true : false;
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
        #endregion
    }
}
